package view.components{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import manager.CategoryManager;
	import manager.PanelManager;
	
	import scaleform.clik.controls.Button;
	import scaleform.clik.controls.DropdownMenu;
	import scaleform.clik.controls.TextInput;
	import scaleform.clik.data.DataProvider;
	
	public class CategoryChoose extends Sprite{
		
		public var ctegoryList:DropdownMenu;  //类别列表
		public var categoryOperator:Button;   //类别创建
		public var flashName:TextInput;	  //动画名称
		
		public function CategoryChoose(){
			addEventListener(Event.ADDED_TO_STAGE,onAddedToStage);
		}
		
		public function nameGroup():void{
			var data:Object = ctegoryList.dataProvider[ctegoryList.selectedIndex];
			var type:String = data.label;
			var value:uint = uint(data.num) + 1;
			data.num = value;
			onChange();
			CategoryManager.changeNum(type,value);
		}
		
		protected function onAddedToStage(event:Event):void{
			viewInit();
			eventInit();
		}
		
		private function viewInit():void{
			var dp:DataProvider = new DataProvider(CategoryManager.categoryArray);
			ctegoryList.dataProvider = dp;
			ctegoryList.selectedIndex = 0;
		}
		
		private function eventInit():void{
			ctegoryList.addEventListener(Event.CHANGE,onChange);
			categoryOperator.addEventListener(MouseEvent.CLICK,onCategoryOperator);
		}
		
		protected function onCategoryOperator(event:MouseEvent):void{
			PanelManager.showCategoryOperator();
		}
		
		protected function onChange(event:Event = null):void{
			var data:Object = ctegoryList.dataProvider[ctegoryList.selectedIndex];
			if(!data){
				flashName.text = '';
				return;
			}
			var prefix:String = data.prefix;
			var index:uint = uint(data.num) + 1;
			var newName:String = prefix + index;
			flashName.text = newName;
		}
	}
}